﻿using System.ComponentModel.DataAnnotations;
using SqlSugar;

namespace sixgod.Model
{
    public abstract class ModelBase
    {
        [SugarColumn(IsPrimaryKey = true, Length = 64)]
        public virtual string Id { get; set; }

        /// <summary>
        /// 是否删除 0否 1是
        /// </summary>
        [SugarColumn(ColumnDescription = "是否删除 0否 1是")]
        public virtual int IsDelete{get;set;} = 0;

        /// <summary>
        /// 创建人
        /// </summary>
        [SugarColumn(ColumnDescription = "创建人", IsOnlyIgnoreUpdate = true,Length = 32)]
        public virtual string? CreateUser { get; set; }

        /// <summary>
        /// 最后修改人
        /// </summary>
        [SugarColumn(ColumnDescription = "最后修改人",Length = 32)]
        public virtual string? UpdateUser { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        [SugarColumn(ColumnDescription = "创建时间", IsOnlyIgnoreUpdate = true)]
        public virtual DateTime CreateTime { get; set; }

        /// <summary>
        /// 最后修改时间
        /// </summary>
        [SugarColumn(ColumnDescription = "最后修改时间")]
        public virtual DateTime UpdateTime { get; set; }

        public virtual void Create(string creator)
        {
            this.Id = Guid.NewGuid().ToString("N");
            this.CreateUser = creator;
            this.UpdateUser = creator;
            SetCurrentTime();
        }
        
        public virtual void Update(string updater)
        {
            SetCurrentTime();
            this.UpdateUser = updater;
        }
        
        private void SetCurrentTime()
        {
            this.CreateTime = DateTime.Now;
            this.UpdateTime = DateTime.Now;
        }


        /// <summary>
        /// 模型数据验证
        /// </summary>
        /// <returns></returns>
        public abstract (bool,string) Verify();
    }
}